Skip to content

feat: 取人脚本支持返回 OperatorKey 与操作者对象,默认模板带创建者身份 (#303) - #304

Merged
xlorne merged 2 commits into
devfrom
feature/issue-303-operator-script-resolver
Dec 3, 2026
Merged

xlorne merged 2 commits into
devfrom
feature/issue-303-operator-script-resolver

Conversation

@xlorne

@xlorne xlorne commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

背景

issue #303:多身份(#288 / #297 / #301)落地后,「脚本产出参与人」这条链路没有升级 —— OperatorLoadScript 把脚本返回值统一 Long.parseLong(String.valueOf(x)),身份在这一步被丢掉,文档 §3.4 的 [$bind.getOperatorByIdentity(2,'department1')] 实际会抛 NumberFormatException。

本 PR 包含 issue 的全部后端改动:解析层 + 脚本 API + 默认模板 + 文档。按维护者要求合并为单一分支 feature/issue-303-operator-script-resolver(原 feature/issue-303-default-script 已快进合入并删除)。

改动

1. 新增统一解析器 OperatorScriptResultResolver

flow-engine-framework/.../script/operator/OperatorScriptResultResolver.java

按元素逐个判定,三种形态允许混用:

元素 处理 身份 回查
IFlowOperator 直接采用 对象自带 getIdentity() 否
OperatorKey 按身份分组批量回查 key.identity() 是
Number / 纯数字字符串 按默认身份批量回查 默认身份 是
null / 空串 / 非正数 id 跳过(存量 [-1] 表示无审批人) — —
其他 FlowValidationException(带脚本类型、元素类型、元素内容) — —

2. 改造调用点

  • OperatorLoadScript#execute:不再强转 List<Object>,直接交给解析器;
  • ErrorTriggerScript:operators 同样支持三种形态(含单值);
  • OperatorLoadStrategy:分配回查改调解析器。

3. 脚本 API

API 返回 说明
request.getCreatedOperatorKey() OperatorKey 创建者 + 创建时身份
request.getCurrentOperatorKey() OperatorKey 当前审批人 + 当前身份
request.getSubmitOperatorKey() OperatorKey 提交人 + 提交时身份
request.findPreviousNodeOperators() List<IFlowOperator> 上一节点实际审批人(含身份)
$bind.getOperatorKey(userId, identity) OperatorKey 只构造标识,不回查

FlowSession 新增 loadPreviousNodeOperators():复用 loadPreviousNodeOperatorIds() 的直接前驱校验与 isAutoDone() 排除,改为按记录的 (currentOperatorId, currentOperatorIdentity) 回查。原 *Id / *Identity / getOperatorByIdentity / findPreviousNodeOperatorIds 全部保留。

FlowGroovyScriptFactory 的脚本描述同步三种返回形态(脚本编辑器的提示文案)。

4. 默认模板与文档

测试

新增 25 例,framework 全量 515 例通过(./mvnw -o -pl flow-engine-framework test):

  • OperatorScriptResultResolverTest(12 例):三种形态、混合列表顺序、单值/null/空列表、null 元素、非正数 id 跳过、同人异身份不合并、非法元素异常上下文、按身份分组回查次数、对象形态不发生回查(代理计数断言);
  • OperatorLoadScriptTest(7 例):getCreatedOperatorKey / $bind.getOperatorByIdentity / $bind.getOperatorKey / 混用顺序 / 单值 / 非法元素;
  • ErrorTriggerScriptTest(+3 例):operators 返回 Key / 对象 / 单个 Key;
  • OperatorScriptIdentityFlowTest(3 例):department1 发起 → 创建者节点审批记录 currentOperatorIdentity = department1;换 department2 发起同理;开始节点调用 findPreviousNodeOperators() 安全返回空列表。

兼容性

  • 存量脚本 return [id1, id2] 行为不变(默认身份);
  • 存量 [-1]「无审批人」语义保留(跳过 → 仍走 errorTrigger);
  • 非法返回值从 NumberFormatException 变为带上下文的 FlowValidationException;
  • 默认模板改为 getCreatedOperatorKey() 后,新建节点审批人身份 = 流程发起时的身份(原为默认身份)。这是 issue 要的效果,但对「已启用多身份、一直用默认模板」的业务是可感知变化;存量流程定义里已保存的脚本文本不受影响,未做数据迁移。

关联

前端同批改动:codingapi/flow-frontend#89(默认脚本 + 变量列表)

Closes #303

脚本返回值不再被强转为 Long,统一由 OperatorScriptResultResolver 解析,
支持 List<Long>(默认身份)、List<OperatorKey>(按身份回查)、
List<IFlowOperator>(直接采用)三种形态,允许同一列表混用。

- 新增 OperatorScriptResultResolver:按身份分组批量回查、按脚本顺序输出,
  非正数 id(存量 -1 表示无审批人)跳过,非法元素抛 FlowValidationException
- OperatorLoadScript / ErrorTriggerScript 统一走解析器
- OperatorLoadStrategy 的分配回查逻辑下沉到解析器
- 脚本 API:request.getCreatedOperatorKey / getCurrentOperatorKey /
  getSubmitOperatorKey / findPreviousNodeOperators,$bind.getOperatorKey
- FlowSession 新增 loadPreviousNodeOperators(保留记录上的身份)
- 脚本工厂的描述同步三种返回形态

Refs #303
- ScriptDefaultConstants 默认取人脚本改为 [request.getCreatedOperatorKey()]
- operator-identity.md §3.4 补齐三种返回形态、默认模板、Key 构造 API 与
  findPreviousNodeOperators 用法;§5 补默认脚本升级的兼容说明

Closes #303
@codecov

codecov Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.26087% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.87%. Comparing base (e007aa5) to head (99204c1).

Files with missing lines Patch % Lines
.../script/operator/OperatorScriptResultResolver.java 74.77% 18 Missing and 10 partials ⚠️
...ngapi/flow/script/request/GroovyScriptRequest.java 50.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##                dev     #304      +/-   ##
============================================
- Coverage     76.00%   75.87%   -0.13%     
- Complexity     2140     2163      +23     
============================================
  Files           282      283       +1     
  Lines          8714     8810      +96     
  Branches       1044     1064      +20     
============================================
+ Hits           6623     6685      +62     
- Misses         1574     1597      +23     
- Partials        517      528      +11     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@xlorne xlorne changed the title feat: 取人脚本支持返回 OperatorKey 与操作者对象 (#303) feat: 取人脚本支持返回 OperatorKey 与操作者对象,默认模板带创建者身份 (#303) Dec 3, 2026
@xlorne
xlorne merged commit b8ef908 into dev Dec 3, 2026
2 of 3 checks passed
@xlorne
xlorne deleted the feature/issue-303-operator-script-resolver branch December 3, 2026 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant